package com.hualan.sfzy.service.psyc.impl;

import com.hualan.sfzy.entity.QuestionReply;
import com.hualan.sfzy.mapper.psyc.QuestionReplyMapper;
import com.hualan.sfzy.service.psyc.QuestionReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;


import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class QuestionReplyImpl implements QuestionReplyService {
    @Override
    public Integer selectCountByQuestionId(Integer questionId) {
        return mapper.selectCountByQuestionId(questionId);
    }

    @Autowired
    private QuestionReplyMapper mapper;

    @Override
    public int add(QuestionReply entity) {
        return mapper.insert( entity);
    }

    @Override
    public int edit(QuestionReply entity) {
        return mapper.update( entity);
    }

    @Override
    public int remove(Integer id) {
        return mapper.delete( id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return mapper.deleteBatch( ids);
    }

    @Override
    public List<QuestionReply> find() {
        return mapper.select( null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, QuestionReply entity) {

        PageHelper.startPage(pageNum, pageSize);
        List<QuestionReply> list = mapper.select( entity);
        PageInfo<QuestionReply> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public QuestionReply findById(Integer id) {
        return mapper.selectById( id);
    }
}
